package com.jiukuaidao.zhulin.module.commodity.model;

import android.content.Context;

import com.jiukuaidao.library.net.IApi;
import com.jiukuaidao.zhulin.entity.ApiSortCatList;
import com.jiukuaidao.zhulin.module.commodity.contract.SortContract;

import java.util.ArrayList;
import java.util.List;

/**
 * Author : H_Joker
 * Date : 2016/6/3
 * Description :
 */
public class SortModel implements SortContract.Model {

    private List<String> mCatNames;

    private Context mContext;

    private List<ApiSortCatList.ApiSortCateListItem> mCateList;

    public SortModel(Context context) {
        mContext = context;
    }


    @Override
    public void loadData(IApi api) {
        loadData(api, true);
    }

    @Override
    public void loadData(IApi api, boolean isBuildParams) {
        loadData(api, isBuildParams, false);
    }

    @Override
    public void loadData(IApi api, boolean isBuildParams, boolean aes) {
        if (isBuildParams)
            api.buildBaseParams();

        if (aes)
            api.aes();
        api.start();
    }

    @Override
    public List<String> getCateNames() {
        return mCatNames;
    }

    @Override
    public void setCatNames(List<String> names) {
        mCatNames = names;
    }

    @Override
    public void setCateList(List<ApiSortCatList.ApiSortCateListItem> list) {
        List<String> names = new ArrayList<>();
        for (ApiSortCatList.ApiSortCateListItem item : list) {
            names.add(item.name);
        }
        setCatNames(names);
        mCateList = list;
    }

    @Override
    public List<ApiSortCatList.ApiSortCateListItem> getCateList() {
        return mCateList;
    }
}
